home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / eckelt01.zip / PAGENUM.CPP < prev    next >
C/C++ Source or Header  |  1995-02-22  |  1KB  |  47 lines

  1. //: PAGENUM.CPP -- put page numbers and date on code listings
  2. #include <fstream.h>
  3. #include <strstream.h>
  4. #include <string.h>
  5. #include <dir.h>
  6. #include "allege.h"
  7. const char* file = "..\\codexref.txt";
  8. ofstream errors("c:\\tmp\\errors.txt", ios::app);
  9.  
  10. main(int argc, char ** argv) {
  11.   allege(argc == 2, "usage: pagenum filename");
  12.   ifstream database(file);
  13.   allegefile(database);
  14.   const sz = 100;
  15.   char buf[sz];
  16.   int flag = 0;
  17.   while(database.getline(buf, sz)) {
  18.      if(strncmp(buf, argv[1], strlen(argv[1])) == 0) {
  19.         flag++; // found match
  20.         char* p = strchr(buf, ']');
  21.         *p = 0;
  22.         p = strchr(buf, '[') + 1;
  23.         ostrstream s;
  24.         {
  25.             ifstream code(argv[1]);
  26.             allegefile(code);
  27.             s << code.rdbuf();
  28.         }
  29.         ofstream newcode(argv[1]);
  30.         allegefile(newcode);
  31.         newcode << "// "
  32.           << p << " in \"Thinking in C++\" by Bruce Eckel"
  33.           << endl << s.rdbuf();
  34.      }
  35.   }
  36.   if(!flag) {
  37.      const bsz = 100;
  38.      char buf[bsz];
  39.      errors << getcwd(buf, bsz)
  40.         << " couldn't find match for " << argv[1] << endl;
  41.   }
  42. }
  43.  
  44.  
  45.  
  46.  
  47.